Skip to content

Fix open redirects in OIDC and Blazor WebAssembly Identity guidance - #38218

Open
oroztocil wants to merge 3 commits into
mainfrom
oroztocil-open-redirect-guidance
Open

oroztocil wants to merge 3 commits into
mainfrom
oroztocil-open-redirect-guidance

Conversation

@oroztocil

@oroztocil oroztocil commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Two articles show return URL handling that allows open redirects, and the open redirect guidance doesn't cover Blazor.

The Blazor code matches the recommended code merged in dotnet/aspnetcore#70796.

Changes:

  • configure-oidc-web-authentication.md and the RazorPageOidc sample: the Login page passed ReturnUrl=//evil.example through and reduced https://host//evil.example to //evil.example. It now uses Url.IsLocalUrl and falls back to the app root.
  • qrcodes-for-authenticator-apps.md: the inline Login component navigated to ReturnUrl without checking it, which also allowed javascript: URLs. It now matches the fixed sample in Validate return URLs in Blazor samples blazor-samples#693.
  • preventing-open-redirects.md: new section on validating return URLs in Blazor apps, both for navigation and for links. It also adds a missing closing fence to the previous code block, which would otherwise swallow the new section.

Validation: the RazorPageOidc sample builds, and the examples in the new section were checked with a small test program.

Fixes #38217


Internal previews

File Preview link
aspnetcore/blazor/security/webassembly/standalone-with-identity/qrcodes-for-authenticator-apps.md Learn preview
aspnetcore/security/authentication/configure-oidc-web-authentication.md Learn preview
aspnetcore/security/authorization/custom-authorization-policies-with-iauthorizationrequirementdata.md Learn preview
aspnetcore/security/preventing-open-redirects.md Learn preview

Build report

@guardrex guardrex left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of comma NITS ... "Because" is considered to always (well, usually 😄) introduce essential information. As an essential clause, it doesn't receive a leading comma.

Note tho in passing that "because" could introduce non-essential info. Usually tho, the author intends the clause to make the meaning of the rest of the sentence clear. In these cases on the PR, it looks like it's important to understand why the behavior is occurring ... that the sentence is meant to explain the reasoning to the reader. Feel free to push back if that isn't the case. I'll approve if you want to treat these clauses as non-essential.

@guardrex guardrex left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge when ready! :shipit:

Actually, I'll change it back to draft since it's on hold right now.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The review reports no active issues with the return-URL hardening and documentation updates.

No open issues 🎉

What changed in this PR

Addresses #38217 by hardening return-URL handling in ASP.NET Core authentication documentation and samples, and extending open-redirect guidance to Blazor.

Changes:

  • Validates OIDC return URLs with Url.IsLocalUrl, falling back to the app root.
  • Restricts the Blazor Identity login component’s return navigation to validated URLs within the app.
  • Adds Blazor guidance for safe navigation and links, and closes an unterminated code block.
File Description
aspnetcore/​security/​preventing-open-redirects.md Adds Blazor return-URL validation guidance and fixes the code fence.
aspnetcore/​security/​authentication/​configure-oidc-web-authentication/​samples/​oidc-net8/​RazorPageOidc/​Pages/​Login.cshtml.cs Validates return URLs before starting the OIDC challenge.
aspnetcore/​security/​authentication/​configure-oidc-web-authentication.md Updates the inline OIDC example to match the safer sample.
aspnetcore/​blazor/​security/​webassembly/​standalone-with-identity/​qrcodes-for-authenticator-apps.md Validates return destinations in the inline Blazor login component.

Review effort: Balanced

@guardrex
guardrex marked this pull request as ready for review November 24, 2026 17:47
@guardrex
guardrex marked this pull request as draft November 24, 2026 17:48
@oroztocil

Copy link
Copy Markdown
Member Author

@guardrex Thank you. I'll wait for agreement on the recommended code shape in the review of the project template change in dotnet/aspnetcore. Then I will use that in all places where we show a similar code (templates, samples, docs, scaffolding).

@oroztocil
oroztocil marked this pull request as ready for review November 25, 2026 11:51
@oroztocil
oroztocil enabled auto-merge (squash) November 25, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OIDC and Blazor WebAssembly Identity articles show return URL handling that allows open redirects

3 participants